﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace QQ2564874169.Core.ORM
{
    public class ChoiceField<T>
    {
        private List<Expression<Func<T, object>>> _express = new List<Expression<Func<T, object>>>();

        public ChoiceField<T> Add(Expression<Func<T, object>> expr)
        {
            _express.Add(expr);
            return this;
        }

        public ChoiceField(params Expression<Func<T, object>>[] expressions)
        {
            _express.AddRange(expressions);
        }

        public string[] GetFields()
        {
            var list = new List<string>();
            foreach (var item in _express)
            {
                var member = item.Body as MemberExpression;
                var unary = item.Body as UnaryExpression;
                member = member ?? unary?.Operand as MemberExpression;
                if (member != null)
                    list.Add(member.Member.Name);
            }

            return list.ToArray();
        }
    }
}
